package lanou.autohome.carouselpic;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.ArrayList;

import lanou.autohome.R;
import lanou.autohome.basetool.NetTool;

/**
 * Created by dllo on 16/8/18.
 */
public class CarouselAdapter extends PagerAdapter implements ViewPager.OnPageChangeListener {

    private ArrayList<String> strings;
    private Context mcontext;
    private ImageView[] islarge;

    public void setIslarge(ImageView[] islarge) {
        this.islarge = islarge;
    }

    public CarouselAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    public void setStrings(ArrayList<String> strings) {
        this.strings = strings;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return strings != null ? Integer.MAX_VALUE :0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        View view = LayoutInflater.from(mcontext).inflate(R.layout.item_carouse , null);
        ImageView imageView = (ImageView) view.findViewById(R.id.imgurl_carouse);

        NetTool netTool = new NetTool();
        netTool.getImage(strings.get(position % strings.size())  , imageView);

        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
        container.removeView((View) object);
    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }


}
